﻿// Copyright (c) Inossem. All rights reserved.
// Licensed under the LGPL-3.0 license. See LICENSE file in the project root for full license information.

using System;
using System.Activities.Tracking;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DWF.Studio.ProcessExecutor.Core.Engine
{
    internal class WorkflowTrackingParticipant : TrackingParticipant
    {
        private Action<string> _excuteTrack;

        public WorkflowTrackingParticipant(Action<string> excuteTrack)
        {
            _excuteTrack = excuteTrack;
        }

        protected override void Track(TrackingRecord trackRecord, TimeSpan timeStamp)
        {
            ActivityStateRecord recordEntry = trackRecord as ActivityStateRecord;

            if (recordEntry != null)
            {
                this._excuteTrack?.Invoke($"[{recordEntry.EventTime.ToLocalTime().ToLongTimeString()}] [{recordEntry.Activity.Id}] [{recordEntry.Activity.Name}]  [{recordEntry.State}]");
            }
        }
    }
}
